#include <bits/stdc++.h>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a, b;
    vector<pair<int, int>> mp(n + 1);
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        mp[i + 1] = {a, b};
    }
    int q;
    cin >> q;
    while(q--){
        cin >> a >> b;
        auto t = mp[a];
        int ans = b % t.first;
        if(ans <= t.second){
            cout << b + t.second - ans << endl;
        }else{
            cout << b + (t.first + t.second - ans) << endl;
        }
    }
    return 0;
}